#!/bin/sh

set -eu

jiapkg_build() {
	snappy_DIR=$($JIAPKG_EXE info --install-dir snappy)

	# FIXME: this sucks.
	#
	# -DCMAKE_REQUIRED_FLAGS="-L$snappy_DIR/lib" to makes pass the check
	# out "check_library_exists".
	#
	# CXXFLAGS to makes cmake find and link "snappy".

	export CXXFLAGS="-L$snappy_DIR/lib -I$snappy_DIR/include -Wl,-rpath=$snappy_DIR/lib"

	cmake -DCMAKE_INSTALL_PREFIX="$JIAPKG_INSTALL_DIR" \
		-DCMAKE_REQUIRED_FLAGS="-L$snappy_DIR/lib" \
		-DLEVELDB_BUILD_BENCHMARKS=OFF \
		-DLEVELDB_BUILD_TESTS=OFF \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_SHARED_LIBS=ON \
		-Bbuild
	cmake --build build -j"$JIAPKG_JOBS"
}

jiapkg_install() {
	cmake --install build --strip
}

case "$1" in
build) jiapkg_build ;;
install) jiapkg_install ;;
esac
